package com.example.thridhero.webchatfragment;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

/**
 * Created by thridHero on 2017/3/24.
 */

public class FriendChatAdapter extends RecyclerView.Adapter<FriendChatAdapter.ViewHolder>{
    private List<Content> mcontentList;

    public FriendChatAdapter(List<Content> contentList){
        mcontentList = contentList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.friend_chat_content,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(FriendChatAdapter.ViewHolder holder, int position) {
        Content content = mcontentList.get(position);
        if(Content.MESSAGE_SEND.equals(content.getSendType())){
            holder.leftLayout.setVisibility(View.GONE);
            holder.rightLayout.setVisibility(View.VISIBLE);
            holder.rightView.setText(content.getContent());
        }else{
            holder.rightLayout.setVisibility(View.GONE);
            holder.leftLayout.setVisibility(View.VISIBLE);
            holder.leftView.setText(content.getContent());
        }
    }

    @Override
    public int getItemCount() {
        return mcontentList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        LinearLayout leftLayout;
        LinearLayout rightLayout;

        TextView leftView ;
        TextView rightView;

        public ViewHolder(View itemView) {
            super(itemView);
            leftView = (TextView) itemView.findViewById(R.id.left_text);
            rightView = (TextView)itemView.findViewById(R.id.right_text);

            leftLayout = (LinearLayout) itemView.findViewById(R.id.left_text_layout);
            rightLayout = (LinearLayout) itemView.findViewById(R.id.right_text_layout);
        }
    }
}
